<template>
  <div class="center-nav-top">
    <div class="data-cards">
      <div class="data-card" v-for="(item, index) in dataCards" :key="index">
        <div class="card-content">
          <div class="card-title">{{ item.title }}</div>
          <div class="card-value">
            <CountUp :end-val="item.value" :duration="2" :options="{ decimalPlaces: item.decimal || 0 }" />
            <span class="unit">{{ item.unit }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import CountUp from '@/components/count-up'

// 数据卡片配置
const dataCards = ref([
  {
    title: '运力车辆总数',
    value: 0,
    unit: '辆',
    decimal: 0
  },
  {
    title: '运力站点总数',
    value: 0,
    unit: '个',
    decimal: 0
  },
  {
    title: '订单总数',
    value: 0,
    unit: '单',
    decimal: 0
  },
  {
    title: '运行总里程',
    value: 0,
    unit: 'km',
    decimal: 1
  }
])

const getNavData = (data: any) => {
  let obj = JSON.parse(data)
  dataCards.value.forEach((item: any) => {
    if(item.title == '运力车辆总数'){
      item.value = Number(obj.totalVehicles)
    }
    if(item.title == '运力站点总数'){
      item.value = Number(obj.totalStations)
    }
    if(item.title == '订单总数'){
      item.value = Number(obj.totalOrders)
    }
    if(item.title == '运行总里程'){
      item.value = Number(obj.totalMileage)
    }
  })
}

defineExpose({
  getNavData
})
</script>

<style lang="less" scoped>
.center-nav-top {
  width: 100%;
  height: 200px;
  padding: 0;
  
  .data-cards {
    display: flex;
    gap: 20px;
    padding: 0 20px;
    box-sizing: border-box;
    height: 100%;
    
    .data-card {
      flex: 1;
      position: relative;
      background-image: url('@/assets/img/topItemBg.png');
      background-size: 100% 100%;
      background-repeat: no-repeat;
      background-position: center;
      height: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
      
      .card-content {
        text-align: center;
        color: #ffffff;
        
        .card-title {
          color: rgba(255, 255, 255, 0.9);
          font-size: 16px;
          margin-bottom: 8px;
          font-weight: 400;
          text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
        }
        
        .card-value {
          color: #ffffff;
          font-size: 28px;
          font-weight: bold;
          line-height: 1;
          display: flex;
          align-items: baseline;
          justify-content: center;
          gap: 4px;
          text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
          
          .unit {
            font-size: 16px;
            color: rgba(255, 255, 255, 0.8);
            font-weight: normal;
          }
        }
      }
    }
  }
}

// 响应式设计
@media (max-width: 1200px) {
  .center-nav-top {
    .data-cards {
      .data-card {
        .card-content {
          .card-title {
            font-size: 14px;
          }
          
          .card-value {
            font-size: 24px;
            
            .unit {
              font-size: 14px;
            }
          }
        }
      }
    }
  }
}
</style>